package com.zc.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zc.mapper.AdminMapper;
import com.zc.pojo.Admin;
import com.zc.service.AdminService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Resource
    private AdminMapper adminMapper;
    // AdminServiceImpl.java
    @Override
    public List<String> getExistingUsernames(Collection<String> usernames) {
        if (usernames.isEmpty()) return Collections.emptyList();

        QueryWrapper<Admin> query = new QueryWrapper<>();
        query.select("username")
                .in("username", usernames)
                .groupBy("username");

        return list(query)
                .stream()
                .map(Admin::getUsername)
                .collect(Collectors.toList());
    }
}

